<template>
	<up-navbar bgColor="transparent">
		<template #left>
			<view class="back" @click="goBack">
				<up-icon size="12" name="arrow-left" color="#fff"></up-icon>
			</view>
		</template>
	</up-navbar>
	<view class="container">
		<view class="carousel">
			<up-swiper :list="(productDatil.goods_images)" @change="change" :autoplay="false"
				indicatorStyle="right: 20px" height="100%">
				<template #indicator>
					<view class="indicator-num">
						<text class="indicator-num__text">{{ currentNum + 1 }}/{{imglen}}</text>
					</view>
				</template>
			</up-swiper>
		</view>

		<view class="introduce-section">
			<view class="price-box">
				<text class="price-tip">¥</text>
				<text class="price">{{productDatil.price}}</text>
			</view>
			<text class="title">{{productDatil.goods_name}}</text>
		</view>

		<view class="c-list">
			<block v-if="attrlen>0">
				<view class="c-row b-b" @click="toggleSpec">
					<text class="tit">选择</text>
					<view class="con">
						<text class="selected-text">
							已选：{{specificItem.sizeNmae || ''}}
						</text>
					</view>
					<view style="padding:0 20rpx;height: 42rpx;border-radius: 10rpx;opacity: 1;
background: #F5F5F5;text-align: center;line-height: 42rpx;font-size: 28rpx;color: #3A3A3A;">
						共{{productDatil.attr.length}}种可选择
					</view>
					<view class="yticon icon-you">
						<up-icon name="arrow-right"></up-icon>
					</view>
				</view>
				<view class="c-row b-b" @click.stop ="toggleSpec">
					<text class="tit"></text>
					<view class="con">
						<text v-for="(item,index) in productDatil.sku" :key="index"
							:style="specificItem.id==item.id?'border:1px solid #0B9EE2;width: 61.88rpx;height: 61.88rpx;margin-right: 20rpx;':'width: 61.88rpx;height: 61.88rpx;margin-right: 20rpx;'">{{item.attr}}</text>
					</view>
					<view class="yticon icon-you"></view>
				</view>
			</block>
			<!-- <view class="c-row b-b">
				<text class="tit">配送</text>
				<view class="bz-list con">
					<text>17:00前下单，预计明日送达，快递配送</text>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">运费</text>
				<view class="bz-list con">
					<text>运费25元，满300元包邮</text>
				</view>
			</view> -->
		</view>

		<!-- 评价 -->
		<view class="eva-section">
			<view class="e-header">
				<text class="tit">评价</text>
				<text>({{comlen}})</text>
				<text class="tip">查看全部</text>
				<text class="yticon icon-you"></text>
			</view>
			<block v-for="(item,index) in commentList.data">
				<view class="eva-box">
					<view class="top">
						<image class="portrait" :src="item.avatar" mode="aspectFill"></image>
						<view class="name-box">
							<text class="name">{{item.nickname || '匿名'}}</text>
							<text class="time">{{item.created_at}}</text>
						</view>
					</view>
					<view class="bottom">
						<text class="con">{{item.comment_content}}</text>
					</view>
				</view>
			</block>
		</view>

		<view class="detail-desc">
			<view class="d-header">
				<text>商品介绍</text>
			</view>
			<up-parse :content="productDatil.content"></up-parse>
		</view>
		<sizepop ref='specification' @chooseItem="parentMethod"></sizepop>
	</view>
</template>

<script>
	import {
		http
	} from 'uview-plus'
	import sizepop from '@/componets/specification-pop/specification-pop.vue'
	export default {
		components: {
			sizepop
		},
		data() {
			return {
				currentNum: 0,
				specificItem: {},
				specClass: 'none',
				specSelected: [],
				shareList: [],
				productDatil: {},
				commentList: {},
				goods_id: '',
				imglen: 0,
				attrlen: 0,
				comlen: 0
			};
		},
		async onLoad(options) {
			this.goods_id = options.goods;
			await http.get('/shop/goods/read', {
				params: {
					goods_id: options.goods
				},
				header: {
					'Content-Type': 'multipart/form-data'
				}
			}).then(res => {
				this.productDatil = res
				this.imglen = res.goods_images.length
				this.attrlen = res.attr.length
				this.specificItem = res.sku[0]
			});
			this.commentList = await http.get('/shop/goods/comment', {
				params: {
					goods_id: options.goods
				},
				header: {
					'Content-Type': 'multipart/form-data'
				}
			})
			this.comlen = this.commentList.data.length
		},
		methods: {
			change(e) {
				this.currentNum = e.current
			},
			//规格弹窗开关
			toggleSpec() {
				var that = this
				console.log(that.$refs.specification)
				that.$refs.specification.setup(that.productDatil.id);
			},
			buy() {
				uni.navigateTo({
					url: `/pages/order/createOrder`
				})
			},
			goBack() {
				uni.navigateBack({
					delta: 2
				})
			},
			parentMethod(e) {
				this.specificItem = e
				console.log(e)
			},
			stopPrevent() {}
		},

	}
</script>

<style lang='scss'>
	page {
		background: #F9F9F9;
		padding-bottom: 160rpx;
	}

	.back {
		width: 64rpx;
		height: 64rpx;
		opacity: 1;
		border-radius: 50%;
		background: rgba(51, 51, 51, 0.5);
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.icon-you {
		font-size: 24rpx;
		color: #888;
	}

	.carousel {
		height: 722rpx;
		position: relative;

		.indicator-num {
			width: 92rpx;
			height: 40rpx;
			border-radius: 20rpx;
			opacity: 1;

			background: rgba(51, 51, 51, 0.5);
			@include flex;
			justify-content: center;
			align-items: center;

			&__text {
				color: #FFFFFF;
				font-size: 28rpx;
			}
		}

	}

	/* 标题简介 */
	.introduce-section {
		background: #fff;
		padding: 20rpx 30rpx;
		width: 718rpx;
		border-radius: 12rpx;
		box-sizing: border-box;
		margin: 16rpx auto;

		.title {
			font-size: 36rpx;
			font-weight: 500;
			height: 50rpx;
			line-height: 50rpx;
			color: #272727;
		}

		.price-box {
			display: flex;
			align-items: baseline;
			height: 64rpx;
			padding: 10rpx 0;
			font-size: 24rpx;
			color: #F03717;
		}

		.price {
			font-size: 48rpx;
		}

		.m-price {
			margin: 0 12rpx;
			color: $font-color-light;
			text-decoration: line-through;
		}

		.coupon-tip {
			align-items: center;
			padding: 4rpx 10rpx;
			background: $uni-color-primary;
			font-size: $font-sm;
			color: #fff;
			border-radius: 6rpx;
			line-height: 1;
			transform: translateY(-4rpx);
		}

		.bot-row {
			display: flex;
			align-items: center;
			height: 50rpx;
			font-size: $font-sm;
			color: $font-color-light;

			text {
				flex: 1;
			}
		}
	}

	.c-list {
		background: #fff;
		width: 718rpx;
		border-radius: 12rpx;
		box-sizing: border-box;
		margin: 16rpx auto;
		font-size: $font-sm;
		color: $font-color-base;
		background: #fff;

		.c-row {
			display: flex;
			align-items: center;
			padding: 20rpx 30rpx;
			position: relative;
		}

		.tit {
			width: 80rpx;
			color: #939393
		}

		.con {
			flex: 1;
			color: $font-color-dark;

			.selected-text {
				margin-right: 10rpx;
			}
		}

		.bz-list {
			height: 40rpx;
			font-size: $font-sm;
			color: $font-color-dark;

			text {
				display: inline-block;
				margin-right: 30rpx;
			}
		}

		.con-list {
			flex: 1;
			display: flex;
			flex-direction: column;
			color: $font-color-dark;
			line-height: 40rpx;
		}

		.red {
			color: $uni-color-primary;
		}
	}

	/* 评价 */
	.eva-section {
		background: #fff;
		padding: 20rpx 30rpx;
		width: 718rpx;
		border-radius: 12rpx;
		box-sizing: border-box;
		margin: 16rpx auto;
		display: flex;
		flex-direction: column;
		padding: 20rpx 30rpx;
		background: #fff;
		margin-top: 16rpx;

		.e-header {
			display: flex;
			align-items: center;
			height: 70rpx;
			font-size: 28rpx;
			color: #9E9E9E;
			;
			border-bottom: 1px solid #EFEFEF;

			.tit {
				font-size: 28rpx;
				color: #3d3d3d;
				margin-right: 4rpx;
			}

			.tip {
				flex: 1;
				text-align: right;
				color: #525252;
			}

			.icon-you {
				margin-left: 10rpx;
			}
		}
	}

	.eva-box {
		display: flex;
		flex-direction: column;
		padding: 20rpx 0;

		.portrait {
			flex-shrink: 0;
			width: 80rpx;
			height: 80rpx;
			border-radius: 100px;
		}

		.top {
			display: flex;
			font-size: 24rpx;
			font-weight: normal;
			letter-spacing: 0px;
			color: #000000;

			.name-box {
				display: flex;
				flex-direction: column;
				margin-left: 10rpx;
			}

			.time {
				color: #9A9A9A;
			}
		}

		.bottom {
			flex: 1;
			font-size: $font-base;
			color: $font-color-base;
			padding-left: 26rpx;

			.con {
				font-size: $font-base;
				color: $font-color-dark;
				padding: 20rpx 0;
			}

			.bot {
				display: flex;
				justify-content: space-between;
				font-size: $font-sm;
				color: $font-color-light;
			}
		}
	}

	/*  详情 */
	.detail-desc {
		margin-top: 16rpx;

		.d-header {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80rpx;
			font-size: $font-base;
			color: $font-color-dark;
			position: relative;

			text {
				padding: 0 20rpx;
				background: #fff;
				position: relative;
				z-index: 1;
			}

			&:after {
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translateX(-50%);
				width: 300rpx;
				height: 0;
				content: '';
				border-bottom: 1px solid #ccc;
			}
		}
	}
</style>